export default class Logger {
    private _bug_levels: Record<string, number> = { "debug": 4, "error": 3, "warn": 2, "info": 1 }
    private _bug_lebel: number = 1
    private _debug: boolean = false

    constructor(debug: boolean, bug_level: string) {
        this._debug = debug
        if (!['debug', 'error', 'warn', 'info'].includes(bug_level.toLocaleLowerCase())) {
            bug_level = "debug"
        }
        this._bug_lebel = this._bug_levels[bug_level] ?? 1
    }

    public info(message: string) {
        if (!this._debug || this._bug_lebel < this._bug_levels["info"]) return;
        const timestamp = new Date().toISOString();
        console.log(`[${timestamp}] ${message}`);
    }

    public error(message: string) {
        if (!this._debug || this._bug_lebel < this._bug_levels["error"]) return;
        const timestamp = new Date().toISOString();
        console.error(`[${timestamp}] ${message}`);
    }

    public debug(message: string) {
        if (!this._debug || this._bug_lebel < this._bug_levels["debug"]) return;
        const timestamp = new Date().toISOString();
        console.debug(`[${timestamp}] ${message}`);
    }

    public warn(message: string) {
        if (!this._debug || this._bug_lebel < this._bug_levels["warn"]) return;
        const timestamp = new Date().toISOString();
        console.warn(`[${timestamp}] ${message}`);
    }
}